
<template>
  <div>
    <!--    <Table
      border
      :columns="getColumn"
      :data="tableData"
      class="ivu-tableStyle1"
      :height="tableHeight"
      v-resize.quiet="getTableHeight"
    >
      <template slot="show_imageNumber" slot-scope="{ row }">
        <span>
          {{ row.imageNumber }} ({{ row.successNumber }}/{{ row.failNumber }})
        </span>
      </template>
      <template slot="show-status" slot-scope="{ row }">
        <div class="buttonStatus">
          <CButton
            v-if="row.status == 1 && row.isHuman == 1"
            :pressed="false"
            class="stastusBtn executing onButton"
            >执行中</CButton
          >
          <CButton
            v-if="row.status == 1 && row.isHuman == 0"
            :pressed="false"
            class="stastusBtn executing onButton"
            >执行中</CButton
          >
          <CButton
            v-if="row.status == 2"
            class="stastusBtn pause onButton"
            :pressed="false"
            >暂停</CButton
          >
          <CButton
            v-if="row.status == 3"
            style="color: #f9b115"
            class="onButton"
            :pressed="false"
            >删除</CButton
          >

          <CButton
            v-if="row.status == 4"
            class="stastusBtn success onButton"
            :pressed="false"
            >完成</CButton
          >
          <CButton
            :pressed="false"
            v-if="row.status == 5"
            class="stastusBtn success onButton"
            >完成</CButton
          >

          <CButton
            v-if="row.status == 6"
            style="color: #f9b115"
            class="onButton"
            :pressed="false"
            >超时</CButton
          >
          <CButton
            v-if="row.status == 7"
            class="stastusBtn stop onButton"
            :pressed="false"
            >停止</CButton
          >
          <CButton
            v-if="row.status == 8"
            class="stastusBtn pending onButton"
            :pressed="false"
            >待执行</CButton
          >
        </div>
      </template>
      <template slot="show-level" slot-scope="{ row }">
        <div v-if="row.status == 8">
          <CSelect
            :disabled="
              $store.getters.getBtnProcessPriority &&
              $store.getters.getBtnProcessPriority.enableFlag == '1'
            "
            horizontal
            :options="priorityShowList"
            :value.sync="row.priority"
            class="prioritySelect onButton"
            @change="selectPriorityChange($event, row)"
          ></CSelect>
        </div>
        <div v-else>{{ row.priority == 0 ? "普通" : "优先" }}</div>
      </template>
      <template slot="action" slot-scope="{ row }">
        &lt;!&ndash;查看&ndash;&gt;
        <CButton
          title="查看子任务"
          variant="outline"
          class="textBtnStyle onButton system-btn-style"
          @click="getInfo(row)"
        >
          查看
        </CButton>
        &lt;!&ndash;详情&ndash;&gt;
        <CButton
          v-if="row.status != 3"
          title="详情"
          variant="outline"
          class="textBtnStyle onButton system-btn-style"
          @click="getTaskDetails(row)"
        >
          详情
        </CButton>
        <CButton
          :disabled="true"
          v-if="row.status == 3"
          title="详情"
          variant="outline"
          class="disableTextBtnStyle onButton"
          @click="() => {}"
        >
          详情
        </CButton>

        &lt;!&ndash;下载&ndash;&gt;
        <CButton
          title="下载"
          v-if="row.status != 2 && row.status != 8"
          variant="outline"
          class="textBtnStyle onButton system-btn-style"
          @click="downloadTaskResult(row)"
        >
          下载
        </CButton>
        <CButton
          :disabled="true"
          title="下载"
          v-if="row.status == 2 || row.status == 8"
          variant="outline"
          class="disableTextBtnStyle onButton"
        >
          下载
        </CButton>

        &lt;!&ndash;暂停&ndash;&gt;
        <CButton
          v-if="row.status == 1 || row.status == 8"
          title="暂停"
          variant="outline"
          class="textBtnStyle onButton system-btn-style"
          @click="pause(row)"
          data-permission="Btn_AllTask_Del"
        >
          暂停
        </CButton>
        <CButton
          :disabled="true"
          v-if="row.status != 1 && row.status != 2 && row.status != 8"
          title="暂停"
          variant="outline"
          class="disableTextBtnStyle onButton"
          @click="() => {}"
          data-permission="Btn_AllTask_Del"
        >
          暂停
        </CButton>

        &lt;!&ndash;恢复&ndash;&gt;
        <CButton
          :disabled="row.status == 2 ? false : true"
          title="恢复"
          v-if="row.status == 2"
          variant="outline"
          class="textBtnStyle onButton system-btn-style"
          @click="restore(row)"
          data-permission="Btn_AllTask_Retore"
        >
          恢复
        </CButton>

        &lt;!&ndash;重启&ndash;&gt;
        <CButton
          :disabled="row.status == 7 ? false : true"
          title="重启"
          v-if="row.status == 7"
          variant="outline"
          class="textBtnStyle onButton system-btn-style"
          @click="reStart(row)"
          data-permission="Btn_AllTask_Restar"
        >
          重启
        </CButton>
        &lt;!&ndash;终止&ndash;&gt;
        <CButton
          :disabled="true"
          title="终止"
          v-if="
            row.status != 1 &&
            row.status != 7 &&
            row.status != 8 &&
            row.status != 2
          "
          variant="outline"
          class="disableTextBtnStyle onButton"
          @click="() => {}"
        >
          终止
        </CButton>
        <CButton
          title="终止"
          v-if="row.status == 1 || row.status == 8 || row.status == 2"
          variant="outline"
          class="textBtnStyle onButton system-btn-style"
          @click="stop(row)"
          data-permission="Btn_AllTask_Restar"
        >
          终止
        </CButton>

        <CButton
          v-if="row.status != 3"
          title="删除"
          variant="outline"
          class="textBtnStyle onButton system-btn-style"
          @click="del(row)"
          data-permission="Btn_QuaCheck_Del"
        >
          删除
        </CButton>
        &lt;!&ndash;  <CButton
          :disabled="true"
          v-if="
            (row.status != 8) &
            (row.status != 1) &
            (row.status != 4) &
            (row.status != 5) &
            (row.status != 6)
          "
          title="删除"
          variant="outline"
          class="disableTextBtnStyle onButton"
          @click="() => {}"
        >
          删除
        </CButton>&ndash;&gt;
      </template>
    </Table>-->
    <TableList
      ref="table"
      :getColumn="getColumn"
      :getAxios="getAxios"
      class="ivu-tableStyle1"
    >
      <template v-slot:show_imageNumber="data">
        <span>
          {{ data.data.row.imageNumber }} ({{ data.data.row.successNumber }}/{{
            data.data.row.failNumber
          }})
        </span>
      </template>
      <template v-slot:show-status="data">
        <div class="buttonStatus">
          <CButton
            v-if="data.data.row.status == 1 && data.data.row.isHuman == 1"
            :pressed="false"
            class="stastusBtn executing onButton"
            >执行中</CButton
          >
          <CButton
            v-if="data.data.row.status == 1 && data.data.row.isHuman == 0"
            :pressed="false"
            class="stastusBtn executing onButton"
            >执行中</CButton
          >
          <CButton
            v-if="data.data.row.status == 2"
            class="stastusBtn pause onButton"
            :pressed="false"
            >暂停</CButton
          >
          <CButton
            v-if="data.data.row.status == 3"
            style="color: #f9b115"
            class="onButton stastusBtn executing"
            :pressed="false"
            >删除</CButton
          >

          <CButton
            v-if="data.data.row.status == 4"
            style="background: #67b9a5;color:white"
            class="onButton stastusBtn executing"
            :pressed="false"
            >成功</CButton
          >
          <CButton
            :pressed="false"
            v-if="data.data.row.status == 5"
           style="background: #c11113;color:white"
            class="onButton stastusBtn executing"
            >失败</CButton
          >

          <CButton
            v-if="data.data.row.status == 6"
            style="color: #f9b115"
            class="onButton stastusBtn executing"
            :pressed="false"
            >超时</CButton
          >
          <CButton
            v-if="data.data.row.status == 7"
            class="stastusBtn stop onButton"
            :pressed="false"
            >停止</CButton
          >
          <CButton
            v-if="data.data.row.status == 8"
            class="stastusBtn pending onButton"
            :pressed="false"
            >待执行</CButton
          >
          <CButton
            v-if="data.data.row.status == 10"
            class="stastusBtn part onButton"
            :pressed="false"
            >部分失败</CButton
          >
        </div>
      </template>
      <template v-slot:show-level="data">
        <div v-if="data.data.row.status == 8 || data.data.row.status == 1">
          <CSelect
            :disabled="
              $store.getters.getBtnProcessPriority &&
              $store.getters.getBtnProcessPriority.enableFlag == '1'
            "
            horizontal
            :options="priorityShowList"
            :value.sync="data.data.row.priority"
            class="prioritySelect onButton selectStyle"
            data-permission="Btn_AllTask_Priority"
            @change="selectPriorityChange($event, data.data.row)"
          ></CSelect>
        </div>

        <div v-else>{{ data.data.row.priority == 0 ? "普通" : "优先" }}</div>
      </template>
      <template v-slot:action="data">
        <Poptip  trigger="hover" word-wrap width="215" class="poptip"  >
          <CButton
              title="查看子任务"
              variant="outline"
              class="textBtnStyle onButton system-btn-style"
              @click="getInfo(data.data.row)"
          >
            查看
          </CButton>
          <!--下载-->
          <!-- <CButton
              title="下载"
              v-if="
              data.data.row.status != 2 &&
              data.data.row.status != -1 &&
              data.data.row.status != 8
            "
              variant="outline"
              class="textBtnStyle onButton system-btn-style"
              @click="downloadTaskResult(data.data.row)"
          >
            下载
          </CButton>
          <CButton
              :disabled="true"
              title="下载"
              v-if="data.data.row.status == 2 || data.data.row.status == 8"
              variant="outline"
              class="disableTextBtnStyle onButton"
          >
            下载
          </CButton> -->
          <!--详情-->
          <CButton
                v-if="data.data.row.status != 3"
                title="详情"
                variant="outline"
                class="textBtnStyle onButton system-btn-style"
                @click="getTaskDetails(data.data.row)"
            >
              详情
            </CButton>
            <CButton
                :disabled="true"
                v-if="data.data.row.status == 3"
                title="详情"
                variant="outline"
                class="disableTextBtnStyle onButton"
                @click="() => {}"
            >
              详情
            </CButton>
          <CButton
              v-if="data.data.row.status != 3"
              title="删除"
              variant="outline"
              class="textBtnStyle onButton system-btn-style"
              @click="del(data.data.row)"
              data-permission="Btn_QuaCheck_Del"
          >
            删除
          </CButton>
         
          <div class="api" slot="content" style="width:200px;
            text-align: center;
            ">
            <!--修改-->
            <!-- <CButton
                v-if="data.data.row.status == 8  && data.data.row.updateAppointmentTimeFlag "
                title="修改预约时间"
                variant="outline"
                class="textBtnStyle onButton system-btn-style"
                @click="modifyMonitor(data.data.row)"
            >
              修改
            </CButton> -->
            <!-- <CButton
              v-if="data.data.row.status == 8  && data.data.row.updateAppointmentTimeFlag == false "
              title="修改预约时间"
              variant="outline"
              class="textBtnStyle onButton system-btn-style"
              @click="modifyWarning()"
            >
              修改
            </CButton> -->
            <!-- <CButton
                :disabled="true"
                v-if="data.data.row.status == 8  && (data.data.row.appointmentTime == '' || data.data.row.appointmentTime == null) "
                title="修改预约时间"
                variant="outline"
                class="disableTextBtnStyle onButton"
                @click="() => {}"
            >
              修改
            </CButton> -->
            <!-- <CButton
                :disabled="true"
                v-if="data.data.row.status != 8"
                title="修改预约时间"
                variant="outline"
                class="disableTextBtnStyle onButton"
                @click="() => {}"
            >
              修改
            </CButton> -->
            <!--详情-->
            <!-- <CButton
                v-if="data.data.row.status != 3"
                title="详情"
                variant="outline"
                class="textBtnStyle onButton system-btn-style"
                @click="getTaskDetails(data.data.row)"
            >
              详情
            </CButton>
            <CButton
                :disabled="true"
                v-if="data.data.row.status == 3"
                title="详情"
                variant="outline"
                class="disableTextBtnStyle onButton"
                @click="() => {}"
            >
              详情
            </CButton> -->
            <!--暂停-->
            <!-- <CButton
                    v-if="data.data.row.status == 1 || data.data.row.status == 8"
                    title="暂停"
                    variant="outline"
                    class="textBtnStyle onButton system-btn-style"
                    @click="pause(data.data.row)"
                    data-permission="Btn_AllTask_Del"
            >
              暂停
            </CButton>
            <CButton
                    :disabled="true"
                    v-if="data.data.row.status != 1 && data.data.row.status != 2 && data.data.row.status != 8"
                    title="暂停"
                    variant="outline"
                    class="disableTextBtnStyle onButton"
                    @click="() => {}"
                    data-permission="Btn_AllTask_Del"
            >
              暂停
            </CButton>-->
            <!--恢复-->
            <!-- <CButton
                    :disabled="data.data.row.status == 2 ? false : true"
                    title="恢复"
                    v-if="data.data.row.status == 2"
                    variant="outline"
                    class="textBtnStyle onButton system-btn-style"
                    @click="restore(data.data.row)"
                    data-permission="Btn_AllTask_Retore"
            >
              恢复
            </CButton>-->
            <!--重启-->
            <CButton
                :disabled="data.data.row.status == 7 ? false : true"
                title="重启"
                v-if="data.data.row.status == 7"
                variant="outline"
                class="textBtnStyle onButton system-btn-style"
                @click="reStart(data.data.row)"
                data-permission="Btn_AllTask_Restar"
            >
              重启
            </CButton>
            <!--终止-->
            <CButton
                :disabled="true"
                title="终止"
                v-if="
            data.data.row.status != 1 &&
            data.data.row.status != 7 &&
            data.data.row.status != 8 &&
            data.data.row.status != 2
          "
                variant="outline"
                class="disableTextBtnStyle onButton"
                @click="() => {}"
            >
              终止
            </CButton>
            <CButton
                title="终止"
                v-if="
            data.data.row.status == 1 ||
            data.data.row.status == 8 ||
            data.data.row.status == 2
          "
                variant="outline"
                class="textBtnStyle onButton system-btn-style"
                @click="stop(data.data.row)"
                data-permission="Btn_AllTask_Restar"
            >
              终止
            </CButton>
          </div>
         
        </Poptip>
      </template>
    </TableList>
    <CModal
      :show.sync="prioShow"
      :closeOnBackdrop="false"
      title="修改优先级"
      centered
    >
      <template #header class="taskExecuteHeader">
        <img
          src="@/assets/icons/modifyred.png"
          alt
          style="width: 43px; height: 43px; margin-top: -4px"
        />
        <p class="delKuangShow">修改优先级</p>
      </template>
      <div class="modalBody">
        <label
          style="margin-right: 41px; display: inline-block; margin-top: 6px"
          >优先级</label
        >
        <RadioGroup
          v-model="priorityData.priority"
          class="m_radio_group"
          style="margin-top: 6px"
        >
          <Radio label="0">普通</Radio>
          <Radio label="1">优先</Radio>
        </RadioGroup>
      </div>
      <template #footer class="footerBtns">
        <CButton @click="prioShow = false" color="info" class="cancel-btn"
          >取消</CButton
        >
        <CButton @click="prioOk" color="info" class="system-btn-style"
          >确定</CButton
        >
      </template>
    </CModal>
    <Modal
      v-model="modifyShow"
      draggable
      scrollable
      title="请填写修改后的预约时间"
      :styles="modalStyle"
    >
      <p slot="header" class="modalHeader">
        <img src="@/assets/icons/shanchu.svg" alt />
        <span style="margin-left: 5px">修改任务预约时间</span>
      </p>
      <span style="margin-right: 38px">预约时间</span>
      <el-date-picker
        v-model="appointmentTime"
        type="datetime"
        maxlength="100"
        value-format="yyyy-MM-dd HH:mm:ss"
        placeholder="请选择预约时间"
        :picker-options="pickerOptions"
      >
      </el-date-picker>
      <div style="height: 17px"></div>
      <template #footer class="footerBtns">
        <CButton @click="modifyShow = false" color="info" class="cancel-btn"
          >取消</CButton
        >
        <CButton @click="modifyOk" color="info" class="system-btn-style"
          >确定</CButton
        >
      </template>
    </Modal>
    <Modal
      v-model="delShow"
      draggable
      scrollable
      title="删除主任务"
      :styles="modalStyle"
    >
      <p slot="header" class="modalHeader">
        <img src="@/assets/icons/shanchu.svg" alt />
        <span style="margin-left: 5px">删除主任务</span>
      </p>
      <div class="modalBody">
        <p>删除主任务时与主任务相关的信息都会丢失</p>
        <p>请确认是否删除?</p>
      </div>
      <template #footer class="footerBtns">
        <CButton @click="delShow = false" color="info" class="cancel-btn"
          >取消</CButton
        >
        <CButton @click="delOk" color="info" class="system-btn-style"
          >确定</CButton
        >
      </template>
    </Modal>
    <Modal
      v-model="pauseShow"
      draggable
      scrollable
      title="暂停任务"
      :styles="modalStyle"
    >
      <p>确认要暂停任务吗？</p>
      <template #footer class="footerBtns">
        <CButton @click="pauseShow = false" color="info" class="cancel-btn"
          >取消</CButton
        >
        <CButton @click="pauseOk" color="info" class="system-btn-style"
          >确定</CButton
        >
      </template>
    </Modal>
    <Modal
      v-model="restoreShow"
      draggable
      scrollable
      title="恢复任务"
      :styles="modalStyle"
    >
      <p>确认要恢复任务吗？</p>
      <template #footer class="footerBtns">
        <CButton @click="restoreShow = false" color="info" class="cancel-btn"
          >取消</CButton
        >
        <CButton @click="restoreOk" color="info" class="system-btn-style"
          >确定</CButton
        >
      </template>
    </Modal>
    <Modal
      v-model="restartShow"
      draggable
      scrollable
      title="重启任务"
      :styles="modalStyle"
    >
      <p>确认要重启任务吗？</p>
      <template #footer class="footerBtns">
        <CButton @click="restartShow = false" color="info" class="cancel-btn"
          >取消</CButton
        >
        <CButton @click="reStartOk" color="info" class="system-btn-style"
          >确定</CButton
        >
      </template>
    </Modal>
    <Modal
      v-model="retryShow"
      draggable
      scrollable
      title="重试任务"
      :styles="modalStyle"
    >
      <p>确认要重试任务吗？</p>
      <template #footer class="footerBtns">
        <CButton @click="retryShow = false" color="info" class="cancel-btn"
          >取消</CButton
        >
        <CButton @click="retryOk" color="info" class="system-btn-style"
          >确定</CButton
        >
      </template>
    </Modal>
    <Modal
      v-model="stopShow"
      draggable
      scrollable
      title="终止任务"
      :styles="modalStyle"
    >
      <p>确认要终止任务吗？</p>
      <template #footer class="footerBtns">
        <CButton @click="stopShow = false" color="info" class="cancel-btn"
          >取消</CButton
        >
        <CButton @click="stopOk" color="info" class="system-btn-style"
          >确定</CButton
        >
      </template>
    </Modal>
    <!-- footer-hide -->
    <Modal
      v-model="showdownLoad"
      draggable
      scrollable
      title="下载列表"
      :styles="modalStyle"
      class="downLoadModal"
    >
      <!-- 复选 : show-checkbox -->
      <Tree
        @on-select-change="selectTree"
        :data="treeData"
        ref="tree"
        class="demo-tree-render"
        style="overflow: auto"
      ></Tree>

      <template #footer class="footerBtns">
        <CButton @click="showdownLoad = false" color="info" class="cancel-btn"
          >取消</CButton
        >
        <CButton @click="downLoadProduct" color="info" class="system-btn-style"
          >下载</CButton
        >
      </template>
    </Modal>

    <div>
      <QualityReport
        ref="refQcReportModal"
        v-show="qcReportModal"
        :modalShow="qcReportModal"
        @closed="qcReportModalClosed"
      ></QualityReport>
    </div>
  </div>
</template>
<script>
import QualityReport from "../qualityCheck/qualityReport";
import TableList from "../../template/table/TableList";
import { debounce } from "lodash";

export default {
  name: "taskTable",
  props: ["modalShow", "taskStatus"],
  components: { QualityReport, TableList },
  data() {
    return {
      modifyShow: false,
      appointmentTime: "",//新增预约时间
      pickerOptions: { //设置此时此刻之前的日期不可选
        disabledDate: function (time) {
          return time.getTime() < Date.now() - 8.64e7;
        },
      },
      timeStart: "",//任务开始时间
      userName: "",
      modalStyle: { top: "200px" },
      tableData: [],
      qcReportModal: false,
      showPop: false,
      pauseShow: false,
      restoreShow: false,
      restartShow: false,
      retryShow: false,
      stopShow: false,
      delShow: false,
      priorityShowList: [
        {
          label: "优先",
          value: 1,
        },
        {
          label: "普通",
          value: 0,
        },
      ],
      clickId: "",
      loading: true,
      pageNum: 1,
      pages: 0,
      total: 0,
      allNum: 0,
      pageSize: 15,
      priority: "",
      dataName: "",//数据名称
      taskSource: "",//数据来源

      groupName: "",
      changestatus: false,
      startTime: "",
      endTime: "",
      prioShow: false, // 修改优先级弹窗
      priorityData: {
        priority: "0",
        startWorkflowId: "",
      },
      productpath: "",
      showdownLoad: false,
      treeData: [],
      tableHeight: 0,
      setIntervalTime: "",
      getAxios: {
        url: this.$api.taskManageApi.query, //请求路径
        method: "get", //请求方式
        dataList: {
          userName: window.sessionStorage.getItem("user"),
          _loadingContainer: document.querySelector(".c-main"),
        }, //请求参数
      },
      webSocket: null,
      // url: '',
    };
  },
  computed: {
    getColumn() {
      if (this.taskStatus !== "8") {
        return [
          {
            key: "groupTaskName",
            title: "任务名称",
            align: "left",
            minWidth: 250,
          },
          {
            key: "taskSourceName",
            title: "任务来源",
            align: "center",
            width: "120",
          },
          {
            key: "taskOwner",
            title: "用户名",
            align: "center",
            width: "120",
          },
          {
            key: "createTime",
            title: "开始时间",
            align: "center",
            width: "170",
          },
          {
            key: "endTime",
            title: "结束时间",
            align: "center",
            width: "170",
          },
          {
            slot: "show-level",
            title: "优先级",
            align: "center",
            width: "120",
          },
          {
            slot: "show_imageNumber",
            title: "景数(成功/失败)",
            align: "center",
            width: "120",
          },
          {
            slot: "show-status",
            title: "状态",
            align: "center",
            width: "100",
          },
          {
            title: "操作",
            width: "210",
            slot: "action",
            align: "center",
          },
        ];
      } else {
        return [
          {
            key: "groupTaskName",
            title: "任务名称",
            align: "left",
            width: "auto",
          },
          {
            key: "taskSourceName",
            title: "任务来源",
            align: "center",
            width: "120",
          },
          {
            key: "taskOwner",
            title: "用户名",
            align: "center",
            width: "120",
          },
          {
            slot: "show-level",
            title: "优先级",
            align: "center",
            width: "120",
          },
          {
            slot: "show-status",
            title: "状态",
            align: "center",
            width: "90",
          },
          {
            title: "操作",
            width: "210",
            slot: "action",
            align: "center",
          },
        ];
      }
    },
  },
  mounted() {
    this.userName = window.sessionStorage.getItem("user");
  },
  methods: {
    getTableHeight(a, b, c, d) {
      this.tableHeight = parseInt(d) - 20 - 51 - 52 - 77 - 120;
    },
    qcReportModalClosed() {
      this.$refs.refQcReportModal.openOrClose();
    },
    // 下载产品 客户端下载
    // downloadTaskResult(item) {

    //   if (item.taskType == 2) {
    //     let path = this.$api.taskManageApi.getTaskProductFile + item.id;
    //     let param = { userName: this.userName };
    //     this.http.get(path, param).then((res) => {
    //       if (res.data.code == 0) {
    //         let data = res.data.data;
    //         let filePath = data.isFile ? data.file : data.file + "/";
    //         let url =
    //           "DownloadFile://" +
    //           sessionStorage.getItem("PIECloud-Token") +
    //           "/" +
    //           this.userName +
    //           "/" +
    //           filePath +
    //           "/";
    //         if (data.isUserFile) {
    //           // isUserFile是不是用户根目录 是，即说明没有文件可以下载
    //           let r = window.confirm("暂无影像产品数据,是否跳转根目录？");
    //           if (r) {
    //             this.$$openDownLoadFile(url);
    //           }
    //         } else {
    //           this.$$openDownLoadFile(url);
    //         }
    //       } else {
    //         this.$Message.error(res.data.message);
    //       }
    //     });
    //   } else {
    //     //质量检查详情
    //     this.$refs.refQcReportModal.openOrClose();
    //     this.$refs.refQcReportModal.getTaskDetails(item, "parent");
    //   }
    // },

    // 下载产品
    downloadTaskResult(item) {
      let _this = this;
      if (/*item.taskType === 2*/ true) {
        //处理加工任务数据
        let path = this.$api.taskManageApi.taskDetailResult + item.id;

        let params = {
         /* productType: 2,*/
          productType: -1,
        };
        this.http.get(path, params).then((res) => {
          if (res.data.code == 0) {
            if (res.data.data.length < 1) {
              this.$Message.warning("暂无影像产品数据");
            } else {
              _this.showdownLoad = true;
              _this.treeData = _this.getNewTreeData(res.data.data);
            }
          } else {
            this.$Message.error(res.data.message);
          }
        });
      } else {
        //质量检查详情
        this.$refs.refQcReportModal.openOrClose();
        this.$refs.refQcReportModal.getTaskDetails(item, "parent");
      }
    },
    downLoadProduct() {
      // this.productpath =
      //   "/pie/data/247/sthx_user_data/pieadmin/lilintest/123/GF3_KAS_QPSI_010970_E81.2_N40.5_20180910_L1A_VH_L10003442728.tif";
      if (!this.productpath) {
        this.$Message.warning("请选择下载的产品文件");
        return;
      }
      /*
        let data = {
          path: this.$api.taskManageApi.isExit,
          params: {
            username: this.$store.state.user.userName,
            path: this.productpath,
            // path:"/pie/data/247/sthx_user_data/pieadmin/lilintest/123/GF3_KAS_QPSI_010970_E81.2_N40.5_20180910_L1A_VH_L10003442728.tif" //测试地址
          },
        };

        let fun = function () {
          let url =
            "DownloadFile://" +
            sessionStorage.getItem("PIECloud-Token") +
            "/" +
            data.params.username +
            "/" +
            data.params.path +
            "/";
          console.log("客户端url：", url);
          window.location.href = url;
        };
        this.$$downLoadFile(data, fun);
        */
      //以前的下载方式
      let newarr = [];
      newarr.push(this.productpath);
      let path = this.$api.taskManageApi.downloadReport + newarr;
      window.open(path);
    },
    //提取文件夹里面所有的文件
    getNewTreeData(data) {
      let _this = this;
      let result = [];
      for (let i = 0; i < data.length; i++) {
        let tempItem = data[i];
        let item = {};
        item.expand = tempItem.expand;
        item.path = tempItem.path;
        item.title = tempItem.title;
        item.type = tempItem.type;
        item.children = [];
        result.push(item);

        if (tempItem.type == "folder" && tempItem.children) {
          let list = [];
          _this.recursiveTreeFile(tempItem.children, list);
          item.children = list;
        }
      }
      return result;
    },
    recursiveTreeFile(data, list) {
      let _this = this;
      for (let i = 0; i < data.length; i++) {
        let tempItem = data[i];
        if (tempItem.type == "file") {
          list.push(tempItem);
        }
        if (tempItem.type == "folder" && tempItem.children) {
          _this.recursiveTreeFile(tempItem.children, list);
        }
      }
      return list;
    },
    // pageSizeChange(val) {

    //   this.pageSize = val;
    // },
    // currentPageChange(val) {
    // console.log('所有任务currentPageChange',val)
    //   this.pageNum = val;
    // },
    initParam(data) {
      this.pageNum = data.pageNum;
      this.pageSize = data.pageSize;
      this.status = data.status;
      this.priority = data.priority;
      this.startTime = data.startTime;
      this.endTime = data.endTime;
      this.groupName = data.name;
      this.taskSource = data.taskSource;
      this.dataName = data.dataName;
      this.tag = data.tag;
    },
    //查询所有流程
    getTaskTableData: debounce(function(data = false) {
      // console.log("refreshed");
      let _this = this;
      _this.tableData = [];
      if (this.endTime == "Invalid date") {
        this.endTime = "";
      }
      if (this.startTime == "Invalid date") {
        this.startTime = "";
      }
   
      // if(_this.groupName == "" && this.dataName != ""){//按 数据名称搜索
      //   let param = {
      //     // currentPageNum: data,
      //     pageNum: _this.pageNum,
      //     pageSize: _this.pageSize,
      //     dataName: _this.dataName,
      //     // _loadingContainer: document.querySelector(".c-main"),
      //   };
      //   this.getAxios.url = this.$api.taskManageApi.queryByDataName;
      //   this.getAxios.dataList = {};
      //   this.$refs.table.getRefreshTable(param);
      //   debugger
      // }else{
        this.getAxios.url = this.$api.taskManageApi.query;//请求路径
        this.getAxios.dataList = {
          userName: window.sessionStorage.getItem("user"),
          _loadingContainer: document.querySelector(".c-main"),
        };
        let param = {
          currentPageNum: data,
          pageNum: _this.pageNum,
          pageSize: _this.pageSize,
          status: _this.status,
          priority: _this.priority,
          taskSource: _this.taskSource,
          startTime: _this.startTime,
          endTime: _this.endTime,
          name: _this.groupName,
          dataName: _this.dataName,
          userName: window.sessionStorage.getItem("user"),
          _loadingContainer: document.querySelector(".c-main"),
        };
        this.$refs.table.getRefreshTable(param);
      // }
      // let param = {
      //   currentPageNum: data,
      //   pageNum: _this.pageNum,
      //   pageSize: _this.pageSize,
      //   status: _this.status,
      //   priority: _this.priority,
      //   taskSource: _this.taskSource,
      //   startTime: _this.startTime,
      //   endTime: _this.endTime,
      //   name: _this.groupName,
      //   userName: window.sessionStorage.getItem("user"),
      //   _loadingContainer: document.querySelector(".c-main"),
      // };
      // this.$refs.table.getRefreshTable(param);
      /* let path = this.$api.taskManageApi.query;
      this.http.get(path, param).then((res) => {
        if (res.data.code == 0) {
          // this.showPop = false;
          _this.tableData = res.data.data.dataList;
          _this.allNum = res.data.data.total;
          _this.total = Math.ceil(res.data.data.total / _this.pageSize);
          for (let i = 0; i < _this.tableData.length; i++) {
            _this.tableData[i].number =
                    (_this.pageNum - 1) * _this.pageSize + i + 1;
            if (_this.tableData[i].endTime == null) {
              _this.tableData[i].endTime = "";
            }
          }
          let info = {};
          info.allNum = _this.allNum;
          info.total = _this.total;
          this.$emit("page-change", info);
        } else {
          // this.showPop = false;
          this.$Message.error("查询失败");
        }
      });*/
    }, 1000),
    modifyWarning(){
      this.$Message.warning("距离任务预约时间不足十分钟，不可修改！")
    },

    modifyMonitor(val) {
      this.modifyShow = true;
      this.clickId = val.id;
      this.appointmentTime = val.appointmentTime; //预约时间回显
      this.timeStart = val.createtTime;//获取开始时间
    },
     modifyOk() { //确认修改
      let _this = this;
      this.modifyShow = false;
      // 接口格式为： /sthx_server/task/taskInfo/api/v1/update/appointmentTime/{appointmentTime}/id/{id}
      let path =
        this.$api.taskManageApi.modifyAppointmentTime +
        this.appointmentTime +
        "/id/" +
        this.clickId;
      // 接口形式为： /sthx_server/task/taskInfo/api/v1/update/appointmentTimeFlag
      // let path1 =
      //   this.$api.taskManageApi.modifyTimeFlag +
      //   "?id=" +
      //   this.clickId +
      //   "&second=600";
      //判断任务的预约时间是否可修改  true为可修改  false为不可修改
      // this.http.get(path1).then((res) => {
      //   if(res.data.code == 0 && res.data.success == true){
      this.http.put(path).then((res) => {
        if (res.data.code == 0) {
          this.$Message.success("修改成功");
          this.$bus.$emit("getTaskCatalog");
          this.getTaskTableData();
        } else {
          this.$Message.error(res.data.message);
        }
      });
    },

    getInfo(val) {
      String.prototype.replaceAll = function (s1, s2) {
        return this.replace(new RegExp(s1, "gm"), s2);
      };

      let userLink =
        `/taskManage/allTask/${val.id}/${val.groupTaskName.replaceAll(
          "/",
          "*"
        )}` + "?";
      this.$router.push({
        path: userLink,
        query: {
          // pageNum: this.pageNum,
          from: "taskLook",
          taskType: val.taskType,
        },
      });
    },
    getTaskDetails(item) {
      // if (item.taskType == 2) {
      this.$router.push({
          path: "/processing",
          query: {
            from: "taskLook",
            id: item.id,
            status: item.status,
          },
      });
      // } else {
      //   this.$Message.info("这是质检任务！");
      //   //  this.$refs.refQcReportModal.openOrClose();
      //   // this.$refs.refQcReportModal.getTaskDetails(item, "parent");
      // }
    },
    //暂停
    pause(val) {
      this.pauseShow = true;
      this.clickId = val.id;
    },

    pauseOk() {
      let _this = this;
      _this.pauseShow = false;
      let statusName = "PAUSED";
      let path = this.$api.taskManageApi.updateStatus + "/" + this.clickId;
      let param = {
        statusName: statusName,
      };
      this.http.put(path, param).then((res) => {
        _this.loading = false;
        if (res.data.code == 0) {
          this.$bus.$emit("getTaskCatalog");
          this.getTaskTableData();
        } else {
          this.$Message.error("状态更改失败");
        }
      });
    },
    //恢复
    restore(val) {
      this.restoreShow = true;
      this.clickId = val.id;
    },
    restoreOk() {
      let _this = this;
      this.restoreShow = false;
      let statusName = "RESUME";
      let path = this.$api.taskManageApi.updateStatus + "/" + this.clickId;
      let param = {
        statusName: statusName,
      };
      this.http.put(path, param).then((res) => {
        _this.loading = false;
        if (res.data.code == 0) {
          this.getTaskTableData();
        } else {
          this.$Message.error("状态更改失败");
        }
      });
    },
    //停止
    stop(val) {
      this.stopShow = true;
      this.clickId = val.id;
    },
    stopOk() {
      let _this = this;
      this.stopShow = false;

      let path = this.$api.taskManageApi.updateStatus + "/" + this.clickId;

      var formdata=new FormData();
      formdata.append("statusName","STOP");

      this.http.put(path, formdata).then((res) => {
        _this.loading = false;
        if (res.data.code == 0) {
          this.$bus.$emit("getTaskCatalog");
          this.getTaskTableData();
        } else {
          this.$Message.error("状态更改失败");
        }
      });
    },
    //重启
    reStart(val) {
      this.restartShow = true;
      this.clickId = val.id;
    },
    reStartOk() {
      let _this = this;
      this.restartShow = false;
      let statusName = "RESTART";
      let path = this.$api.taskManageApi.updateStatus + "/" + this.clickId;
      console.log("612restartOk", path);
      let param = {
        statusName: statusName,
      };
      this.http.put(path, param).then((res) => {
        _this.loading = false;
        if (res.data.code == 0) {
          this.getTaskTableData();
        } else {
          this.$Message.error("状态更改失败");
        }
      });
    },

    del(val) {
      this.delShow = true;
      this.clickId = val.id;
    },
    delOk() {
      let _this = this;
      this.delShow = false;
      let path = this.$api.taskManageApi.delete + this.clickId;
      this.http.delete(path).then((res) => {
        if (res.data.code == 0) {
          this.$Message.success("删除成功");
          this.$bus.$emit("getTaskCatalog");
          this.getTaskTableData();
        } else {
          this.$Message.error("删除失败");
        }
      });
    },
    //重试
    retry(val) {
      this.retryShow = true;
      this.clickId = val.id;
    },
    retryOk() {
      let _this = this;
      this.retryShow = false;
      let statusName = "RETRY";

      let path = this.$api.taskManageApi.updateStatus + this.clickId;
      let param = {
        statusName: statusName,
      };
      this.http.put(path, param).then((res) => {
        _this.loading = false;
        if (res.data.code == 0) {
          this.getTaskTableData();
        } else {
          this.$Message.error("状态更改失败");
        }
      });
    },
    selectTree() {
      let item = this.$refs.tree.getSelectedNodes()[0];
      if (!item) return;
      this.productpath = this.$refs.tree.getSelectedNodes()[0].path;
      if (item.type === "folder") {
        item.expand = !item.expand;
        item.selected = !item.selected;
        return;
      }
    },

    changePriority(data) {
      this.prioShow = true;
      this.priorityData.startWorkflowId = data.id;
    },
    prioOk() {
      let _this = this;
      let url =
        this.$api.taskManageApi.updateTaskPriority +
        this.priorityData.priority +
        "/" +
        this.priorityData.startWorkflowId;
      this.http
        .put(url)
        .then((res) => {
          if (res.data.code == 0) {
            this.prioShow = false;
            this.$Message.success("修改成功");
            // 修改成功后 刷新右侧table
            _this.getTaskTableData();
          } else {
            this.$Message.error(res.data.message);
          }
        })
        .catch((err) => {
          console.log("catch");
          this.prioShow = false;
          this.$Message.error("修改失败");
        });
    },
    /*    selectPriorityChange(event, item) {
      let _this = this;
      let priority = event.target.value;
      let startWorkflowId = item.id;

      let url =
                _this.$api.taskManageApi.updateTaskPriority +
                priority +
                "/" +
                startWorkflowId;

      this.http
                .put(url)
                .then((res) => {
                  if (res.data.code == 0) {
                    this.$Message.success("修改成功");
                    // 修改成功后 刷新右侧table
                    // _this.getTaskTableData(this.groupId);
                  } else {
                    this.$Message.error(res.data.message);
                  }
                  // 修改后,不论成功与否，都刷新右侧table
                  _this.getTaskTableData();
                })
                .catch((err) => {
                  this.$Message.error("修改失败");
                });
    },*/
    selectPriorityChange(event, item) {
      let _this = this;
      let priority = event.target.value;
      let startWorkflowId = item.id;

      let url =
        _this.$api.taskManageApi.updateTaskPriority +
        priority +
        "/" +
        startWorkflowId;
      this.http
        .put(url)
        .then((res) => {
          if (res.data.code == 0) {
            this.$Message.success("修改成功");
            // 修改成功后 刷新右侧table
            // _this.getTaskTableData(this.groupId);
          } else {
            this.$Message.error(res.data.message);
          }
          // 修改后,不论成功与否，都刷新右侧table

          _this.getTaskTableData();
        })
        .catch((err) => {
          this.$Message.error("修改失败");
        });
    },
    initSocket(){
      const url = "ws://36.112.11.166:30800/sthx_server/task/ws";
      this.webSocket = new WebSocket(url);
      this.webSocket.onopen = this.webSocketOnOpen;
      this.webSocket.onclose = this.webSocketOnClose;
      this.webSocket.onmessage = this.webSocketOnMessage;
      this.webSocket.onerror = this.webSocketOnError;
    },
    webSocketOnOpen(){
      console.log("Websocket connected.");
      const userId = window.sessionStorage.getItem("userId");
		  const msg =
        '{"userId": ' +
        userId +
        ',"taskId": ' +
        '"refresh"' +
        ',"type": "task","topic":"conn"}';
      this.webSocket.send(msg);
    },
    webSocketOnClose(){
      this.webSocket.close();
      console.log("WebSocket disconnected.");
    },
    webSocketOnMessage(res){
        const data = JSON.parse(res.data);
        if(data.type="refresh"){
          this.getTaskTableData(true);
          this.$bus.$emit("getTaskCatalog");
        }
    },
    webSocketOnError(res){
      console.log("Connected failed.")
      console.log(res);
    }
  },
  activated() {
    let that = this;
    that.getTaskTableData(true);
    that.$bus.$emit("getTaskCatalog");
    /*
    this.setIntervalTime = setInterval(function () {
      that.getTaskTableData(true);
      that.$bus.$emit("getTaskCatalog");
    }, 5000);
    */
  },
  deactivated() {
    // clearInterval(this.setIntervalTime);
  },
  created(){
    this.initSocket();
  },
  destroyed(){
    this.webSocket.close();
  }
};
</script>
<style scoped>
.onButton:hover {
  color: white;

}
/* .api{
  overflow-wrap: inherit;
    width: 215px;
    overflow-x: hidden;
    display: flex;
    align-items: center;
    /* justify-content: center; */
    /* overflow: hidden; */
    /* flex-direction: row; */
    /* align-items: center; */
    /* float: none; */
    /* overflow-y: inherit; */
/* }  */
.buttonStatus /deep/ .btn:focus {
  -webkit-box-shadow: 0 0 0 0;
  box-shadow: 0 0 0 0;
}
/deep/.ivu-tableStyle1 .ivu-table-body {
  overflow-x: auto;
}

/* 解决下拉选择的显示不全问题  */
.selectStyle {
  margin: 0;
}
/deep/.form-control {
  padding: 0;
}

/*/deep/.ivu-table table{
  width: auto!important;
}*/
</style>
